/*
 * Classname: OperatorDaoImpl.java
 * 
 * Version information
 *
 * Date: 2007-6-28
 * 
 * Copyright DMX
 */

package com.dmx.fw.dao.hibernateimpl;

import java.util.List;

import com.dmx.fw.bean.mapping.pojo.Operator;
import com.dmx.fw.bean.mapping.pojo.ParameterData;
import com.dmx.fw.dao.hibernateimpl.BaseDaoImpl;
import com.dmx.fw.dao.interfaces.OperatorDao;

/**
 * Description: Operator Dao Implementation.
 * 
 * @author Peter Wei
 * @version 1.0 2007-6-28
 */
public class OperatorDaoImpl extends BaseDaoImpl implements OperatorDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.bee.moss.dao.interfaces.OperatorDao#saveOrUpdate(com.bee.moss.bean.mapping.pojo.Operator)
	 */
	public void saveOrUpdate(Operator operator) {
		getHibernateTemplate().saveOrUpdate(operator);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.bee.moss.dao.interfaces.OperatorDao#getRolesById(java.lang.Long)
	 */
	public List getRolesById(Long optrId) {
		String hql = "select role from Role as role inner join fetch role.operators o where o.id=?";
		return getHibernateTemplate().find(hql, optrId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.bee.moss.dao.interfaces.OperatorDao#findByLoginName(java.lang.String)
	 */
	public List findByLoginName(String loginName) {
		String hql = "from Operator where status='1' and login=?";
		return getHibernateTemplate().find(hql, loginName);
	}

	public List getOpratorTypes() {
		String hql = "from ParameterData where status='1' and type_code='OPERATOR_TYPE'";
		return getHibernateTemplate().find(hql);
	}

	public ParameterData getParameterDataByCode(String code) {
		String hql = "from ParameterData where status='1' and code=?";
		List tmp = (List)getHibernateTemplate().find(hql ,code);
		return tmp==null||tmp.isEmpty()?null:(ParameterData)tmp.get(0);
	}

	public List getAllRoles() {
		String hql = "from Role";
		return getHibernateTemplate().find(hql);
	}
}
